<!-- 用户端-我的-领券中心页面 -->
<template>
	<view class="background">
		<view class="card" v-for="(item,index) in coupons" :key="index">
			<view class="left" v-if="item.type==1">
				<view class="signal">
					￥
					<text class="cardvalue">
						{{item.preferentialMoney}}
					</text>
				</view>
				<view class="condition">
					满{{item.triggerMoney}}元可用
				</view>
			</view>
			<view class="left" v-if="item.type==2">
				<view class="signal">
					<text class="cardvalue">
						{{item.discount}}
					</text>
					折
				</view>
			</view>
			<view class="line"></view>
			<view class="right">
				<view class="right-top" v-if="item.source==0">
					通用
				</view>
				<view class="right-top" v-if="item.source==1">
					仅限xx加油站使用
				</view>
				<view class="right-bottom">
					<view class="date">
						{{item.start}}至{{item.end}}
					</view>
					<button @click="Receive(item.id)">使用</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				coupons: [],
				coupon: {},
				money: null
			}
		},
		onLoad(e) {
			this.getcoupon();
			console.log(e);
			this.money = e.money
		},
		methods: {
			async getcoupon() {
				uni.request({
					url: "http://localhost:8080/coupon/coupon_admin/list",
					header: {
						'Authorization': 'Bearer ' + uni.getStorageSync('token')
					},
					method: 'GET',
					success: (resp) => {
						console.log(resp.data);
						this.coupons = resp.data.rows; // 在此步可以获取到数据  

					}
				})
			},
			async Receive(e) {
				console.log(e)
				const response = await uni.request({
					url: `http://localhost:8080/coupon/coupon_admin/${e}`, // 使用正确的模板字符串拼接 URL
					header: {
						'Authorization': 'Bearer ' + uni.getStorageSync('token')
					},
					method: 'GET',
					success: (resp) => {
						console.log(resp);
						this.coupon = resp.data.data
						this.judgment(resp.data.data)
					},
					
				})
				},
				async judgment(e){
					console.log(e);
				if (this.coupon.discount == null) {
					if (this.money >= e.triggerMoney) {
						uni.navigateTo({
							url: "/pages/confirmTheOrder/confirmTheOrder?id=" + e.id
						})
					} else {
						uni.showToast({
							title: '未满足优惠条件',
							icon: 'success',
							duration: 2000 // 显示时间，单位为毫秒，默认为1500
						});
					}
				} else {
					uni.navigateTo({
						url: "/pages/confirmTheOrder/confirmTheOrder?id=" + e.id
					})
				}
				}
			
		}
	}
</script>

<style>
	.background {
		/* 居中三剑客 */
		display: flex;
		flex-direction: column;
	}

	.card {
		width: 710rpx;
		height: 228rpx;
		margin-left: 28rpx;
		display: flex;
		flex-direction: row;
	}

	.left {
		width: 230rpx;
		height: 188rpx;

		border: 3rpx solid #A1B0CB;
		border-radius: 20rpx;
		background-color: #1D6FFF;
		margin-top: 20rpx;
		margin-left: 4rpx;

	}

	.cardvalue {
		color: aliceblue;
		font-size: 54rpx;
		/* 居中三剑客 */
		/* 	display: flex;
		align-items: center;
		justify-content: center; */
	}

	.signal {
		color: aliceblue;
		margin-left: 52rpx;
		margin-top: 70rpx;
		font-size: 35rpx;
		font-weight: 500;
	}

	.condition {
		color: aliceblue;
		margin-top: 8rpx;
		margin-left: 28rpx;
	}

	.line {
		border-left: 2rpx dashed #CECECE;
		height: 148rpx;
		width: 2rpx;
		margin-left: 14rpx;
		margin-top: 40rpx;
	}

	.right {}

	.right-top {
		margin-left: 34rpx;
		margin-top: 56rpx;
		font-size: 30rpx;
		font-weight: 600;
		color: #5A5A5A;
	}

	.right-bottom {
		margin-top: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: row;
	}

	.date {
		margin-right: 15rpx;
		font-size: 24rpx;
		margin-left: 35rpx;
		color: #EC3524;
	}

	button {
		background-color: #1D6FFF;
		color: aliceblue;
		height: 60rpx;
		width: 130rpx;
		font-size: 24rpx;
		font-weight: 550;
		/* 	margin-top: 140rpx; */
	}
</style>